<template>
  <div class="asideList">
    <div v-if="asideList.length!==0">
      <p class="desc">
        <svg-icon icon-class="table"></svg-icon>
        <span>热门文章</span>
      </p>
      <ul class="aside-article-list">
        <li class="item" :key="item.id" v-for="(item, index) in asideList">
          <span class="index">{{index + 1}}</span>
          <span class="title" @click="toArcticle(item._id)">
            {{item.title}}
          </span>
          <span class="readnum">({{item.readingQuantity}})</span>
        </li>
      </ul>
    </div>
    <!-- <div v-if="asideList.length===0">
      lll
    </div> -->
  </div>
</template>

<script>
export default {
  name: 'asideList',
  data() {
    return {
      asideList: []
    }
  },
  created() {
    this.getSearch()
  },
  methods: {
    getSearch() {
      this.$store.dispatch('GetAsideList').then((res) => {
        this.asideList = res
      })
    },
    toArcticle(id) {
      this.$router.push(`/article/${id}`)
    }
  }
}
</script>

<style lang="scss" scoped>
.asideList {
  .desc {
    padding: 10px;
    margin-bottom: 0;
    font-size: 14px;
    font-weight: 400;
    background-color: rgba(255, 255, 255, 0.5)
  }
  .aside-article-list {
    padding: 10px;
    .item {
      position: relative;
      height: 28px;
      line-height: 28px;
      font-size: 17px;
      display: flex;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      &::before {
        content: "";
        position: absolute;
        left: 24px;
        bottom: 0;
        width: 100%;
        height: 28px;
        transform: scaleX(0);
        background: rgba(255,255,255,0.5);
        transition: transform .2s;
        transform-origin: 100% 0;
      }
      &:hover::before {
        transform: scaleX(1);
        transform-origin: 0 0;
      }
    }
    .index {
      display: inline-block;
      flex: 0 0 20px;
      width: 20px;
      height: 20px;
      line-height: 20px;
      text-align: center;
      color: #666;
      background-color: rgba(255, 255, 255, 0.5)
    }
    .title {
      margin: 0 5px;
      padding-left: 8px;
      height: 28px;
      line-height: 28px;
      width: 200px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      font-size: 14px;
      cursor: pointer;
      z-index: 2;
    }
    .readnum {
      font-size: 15px;
      color: #666;
      font-size: 12px;
    }
  }
}
</style>
